/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PainelMalha.java
 *
 * Created on 29/09/2010, 14:41:07
 */
package aprendizadosemfio.Montagem;

import aprendizadosemfio.entidades.Imagens;
//import guarasredes.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import javax.swing.ImageIcon;

/**
 *
 * @author leonardo
 */
public class PainelMalha extends javax.swing.JPanel {

    public ImageIcon img;
    public int vert, hor;
    public boolean pressed = false;
    private ArrayList<Imagens> figuras = new ArrayList<Imagens>();
    Color verde = new Color(94, 174, 70);
    Color vermelha = new Color(238, 172, 182);

    /** Creates new form PainelMalha */
    public PainelMalha() {
        initComponents();

    }

    public void setFiguras(ArrayList<Imagens> figuras) {
        this.figuras = figuras;
    }

    public PainelMalha(BorderLayout border) {

        super(border);
        initComponents();
        this.paintBorder(this.getGraphics());
    }

    @Override
    public void paint(Graphics g) {
        super.paint(g);
        g.setColor(Color.LIGHT_GRAY);

        for (int i = 0; i < this.getWidth();) {
            g.drawLine(i, 0, i, this.getHeight());
            g.drawLine(0, i, this.getWidth(), i);
            i = i + 40;
        }
        for (int i = 0; i < figuras.size(); i++) {
            if (!figuras.get(i).getTipo().equals("muro") && !figuras.get(i).getTipo().equals("impressora")) {
                g.setColor(verde);

                if (figuras.get(i).getRange() <= 5) {
                    g.drawOval(figuras.get(i).getPositionX() - 83, figuras.get(i).getPositionY() - 64, 100, 100);
                    g.drawOval(figuras.get(i).getPositionX() - 84, figuras.get(i).getPositionY() - 65, 102, 102);
                    g.drawOval(figuras.get(i).getPositionX() - 85, figuras.get(i).getPositionY() - 66, 104, 104);

                    g.drawOval(figuras.get(i).getPositionX() - 93, figuras.get(i).getPositionY() - 75, 120, 120);
                    g.drawOval(figuras.get(i).getPositionX() - 94, figuras.get(i).getPositionY() - 76, 122, 122);
                    g.drawOval(figuras.get(i).getPositionX() - 95, figuras.get(i).getPositionY() - 77, 124, 124);

                    g.drawOval(figuras.get(i).getPositionX() - 103, figuras.get(i).getPositionY() - 85, 140, 140);
                    g.drawOval(figuras.get(i).getPositionX() - 104, figuras.get(i).getPositionY() - 86, 142, 142);
                    g.drawOval(figuras.get(i).getPositionX() - 105, figuras.get(i).getPositionY() - 87, 144, 144);

                } else if (figuras.get(i).getRange() <= 10) {
                    g.drawOval(figuras.get(i).getPositionX() - 113, figuras.get(i).getPositionY() - 95, 160,160);
                    g.drawOval(figuras.get(i).getPositionX() - 114, figuras.get(i).getPositionY() - 96, 162, 162);
                    g.drawOval(figuras.get(i).getPositionX() - 115, figuras.get(i).getPositionY() - 97, 164, 164);

                    g.drawOval(figuras.get(i).getPositionX() - 123, figuras.get(i).getPositionY() - 105, 180, 180);
                    g.drawOval(figuras.get(i).getPositionX() - 124, figuras.get(i).getPositionY() - 106, 182, 182);
                    g.drawOval(figuras.get(i).getPositionX() - 125, figuras.get(i).getPositionY() - 107, 182, 184);

                    g.drawOval(figuras.get(i).getPositionX() - 133, figuras.get(i).getPositionY() - 115, 200, 200);
                    g.drawOval(figuras.get(i).getPositionX() - 134, figuras.get(i).getPositionY() - 116, 202, 202);
                    g.drawOval(figuras.get(i).getPositionX() - 135, figuras.get(i).getPositionY() - 117, 204, 204);

                } else if (figuras.get(i).getRange() > 10) {
                    g.drawOval(figuras.get(i).getPositionX() - 143, figuras.get(i).getPositionY() - 125, 220, 220);
                    g.drawOval(figuras.get(i).getPositionX() - 144, figuras.get(i).getPositionY() - 126, 222, 222);
                    g.drawOval(figuras.get(i).getPositionX() - 145, figuras.get(i).getPositionY() - 127, 224, 224);

                    g.drawOval(figuras.get(i).getPositionX() - 153, figuras.get(i).getPositionY() - 135, 240, 240);
                    g.drawOval(figuras.get(i).getPositionX() - 154, figuras.get(i).getPositionY() - 136, 242, 242);
                    g.drawOval(figuras.get(i).getPositionX() - 155, figuras.get(i).getPositionY() - 137, 242, 244);

                    g.drawOval(figuras.get(i).getPositionX() - 163, figuras.get(i).getPositionY() - 145, 260, 260);
                    g.drawOval(figuras.get(i).getPositionX() - 164, figuras.get(i).getPositionY() - 146, 262, 262);
                    g.drawOval(figuras.get(i).getPositionX() - 165, figuras.get(i).getPositionY() - 147, 264, 264);

                } else
                    System.out.println("range tá grande pra caramba");
            }
            g.drawImage(figuras.get(i).getImagem().getImage(), figuras.get(i).getPositionX() - 64, figuras.get(i).getPositionY() - 48, this);

            if (figuras.get(i).getNome() != null) {
                g.setColor(Color.BLACK);
                g.drawString(figuras.get(i).getNome(), figuras.get(i).getPositionX(), figuras.get(i).getPositionY() + 20);
            }
        }




    }

    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        if (img != null) {
            g.drawImage(img.getImage(), hor - 64, vert - 48, this);
        }


    }

    public void ajustaPainel() {
        setSize(this.getParent().getSize());
    }

    public void setHor(int hor) {
        this.hor = hor;
    }

    public void setVert(int vert) {
        this.vert = vert;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 398, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 298, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    public void setImg(ImageIcon img) {
        this.img = img;
    }

    public void mouseDragged(MouseEvent e) {
        if (img != null) {
            img.paintIcon(this, this.getGraphics(), e.getX(), e.getY());
        }
    }

    public void setPressed(boolean pressed) {
        this.pressed = pressed;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
